﻿<!doctype html>
<html>
<head>
	<meta charset="utf-8" />
	<title>自动优化上下架时间报表</title>
    <link href="css/mycss.css" rel="stylesheet" type="text/css">
    <link href="css/pagination.css" rel="stylesheet" type="text/css">
    <link href="http://a.tbcdn.cn/s/kissy/1.3.0/css/dpl/??base-min.css,badges-min.css,icons-min.css,labels-min.css,tables-min.css" rel="stylesheet" type="text/css">
    <link href="http://a.tbcdn.cn/s/kissy/1.3.0/??button/assets/dpl-min.css,calendar/assets/dpl-min.css,menu/assets/dpl-min.css,combobox/assets/dpl-min.css,menubutton/assets/dpl-min.css,overlay/assets/dpl-min.css,split-button/assets/dpl-min.css,tabs/assets/dpl-min.css,toolbar/assets/dpl-min.css,tree/assets/dpl-min.css" rel="stylesheet" type="text/css">
	<script src="http://a.tbcdn.cn/s/kissy/1.3.0/kissy.js" charset="utf-8"></script>
	<script src="javascript/pagination.js"></script>
	<script src="dwr/interface/OnSaleService.js"></script>
	<script src="dwr/engine.js"></script>
	<script type="text/javascript">
	KISSY.getScript("http://l.tbcdn.cn/apps/top/x/sdk.js?appkey="+KISSY.Cookie.get("appkey"));
	
	//包配置 
    KISSY.config({
      packages:[
          {
            name:"gallery",
            path:"http://a.tbcdn.cn/s/kissy/",
            charset:"utf-8"
          }
        ]
    });
    KISSY.use("gallery/kcharts/1.1/linechart/index",function(S,LineChart){
    	OnSaleService.getLog(function(data){
    		var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    		var week = new Array();
    		var array = new Array();
    		for(var i=0;i<weekDay.length;i++){
    			var date = new Object();
    			date.week = weekDay[(new Date().getDay()+i+1)%7];
    			date.value = 0;
    			week.push(date.week);
    			array.push(date);
    		}
    		for(var i=0;i<data.length;i++){
    			var index = weekDay[new Date(data[i].createDate).getDay()];
    			for(var j=0;j<array.length;j++){
    				if(array[j].week==index){
    					array[j].value = data[i].size; 
    				}
    			}
    		}
    		var linechart = new LineChart({
	            renderTo:"#report",
	            title:{
	                content:"最近1周上架统计",
	                css:{}
	            },
	            anim:{},
	            lineType: "arc",
	            themeCls: "ks-chart-default",
	            comparable: false,
	            xAxis: {
	                text: week
	            },
	            yAxis:{
	                min:0
	            },
	            series:[{
	                data: array
	            }],
	            defineKey:{
	                x:"week",
	                y:"value"
	            },
	            tip:{
	                template:"上架次数：<span>{{value}}</span> 件<br/>"
	            }
	        });
    	});
    });
	</script>
	<script type="text/template" id="default-pagination-tpl"> 
        {{#! 显示首页 }}
        {{#if currentPage === startPage }}
        <a class="pg-prev pg-first pg-disabled" href="#">首页</a>
        {{#else}}
        <a class="pg-prev pg-first" href="#" data-page="{{ startPage }}">首页</a>
        {{/if}}
 
        {{#! 显示上一页 }}
        {{#if currentPage === startPage }}
        <a class="pg-prev pg-disabled">上一页</a>
        {{#else}}
        <a class="pg-prev" href="#" data-page="{{ currentPage - 1 }}">上一页</a>
        {{/if}}
 
        {{#if showPageNum }}
        {{#! 左边固定显示几页, 如固定显示 1 和 2 }}
        {{#if currentPage > startPage + alwaysDisplayCount - 1}}
        {{#for var i = 0; i < alwaysDisplayCount; i++ }}
        {{#! 避免后面重复显示 }}
        {{#if i + startPage < startIndex }}
        <a class="pg-page pg-item" href="#" data-page="{{ i + startPage }}">{{ i + startPage }}</a>
        {{/if}}
        {{/for}}
        {{/if}}
 
        {{#! 是否显示省略号 }}
        {{#if ellipseText && startIndex > startPage + alwaysDisplayCount }}
        <span class="pg-item">…</span>
        {{/if}}
 
        {{#! 显示页数 }}
        {{#for var i = startIndex; i <= endIndex; i++ }}
        {{#if currentPage !== i }}
        <a class="pg-page pg-item" href="#" data-page="{{ i }}">{{ i }}</a>
        {{#else}}
        <span class="pg-current pg-item">{{ i }}</span>
        {{/if}}
        {{/for}}
 
        {{#! 是否显示省略号 }}
        {{#if ellipseText && endIndex < endPage - alwaysDisplayCount }}
        <span class="pg-item">…</span>
        {{/if}}
 
        {{#! 右边固定显示几页 }}
        {{#if currentPage < endPage - alwaysDisplayCount + 1 }}
        {{#for var i = endPage - alwaysDisplayCount + 1; i <= endPage; i++ }}
        {{#if i > endIndex }}
        <a class="pg-page pg-item" href="#" data-page="{{ i }}">{{ i }}</a>
        {{/if}}
        {{/for}}
        {{/if}}
        {{/if}}
 
        {{#! 显示下一页 }}
        {{#if currentPage === endPage }}
        <a class="pg-next pg-disabled">下一页</a>
        {{#else}}
        <a class="pg-next" href="#" data-page="{{ currentPage + 1 }}">下一页</a>
        {{/if}}
 
        {{#! 显示末页 }}
        {{#if currentPage === endPage }}
        <a class="pg-next pg-last pg-disabled" href="#">末页</a>
        {{#else}}
        <a class="pg-next pg-last" href="#" data-page="{{ endPage }}">末页</a>
        {{/if}}
    </script>
</head>
<body>
	<!--主体内容-->
	<div id="content">
	    <!-- 功能描述 -->
	    <div style="padding: 20px 0px;">
	        <div class="ks-popup-inner">
	            <h3 class="ks-popup-title">自动优化上下架时间报表</h3>
	            <div class="ks-popup-content">
	                <p>And here's some amazing content. It's very engaging. right?</p>
	            </div>
	        </div>
	    </div>
	    <!-- 自动上架 报表-->
	    <div class="ks-chart-wrapper" id="report" style="height:400px">
        	<div class="loading">loading</div>
        </div>
		<!-- 详细报表 -->
        <table class="table" id="logs">
        	<caption><h3 class="ks-popup-title">自动优化上下架详细报表</h3></caption>
            <thead>
                <tr>
                	<th width="60">时间</th>
                	<th width="50">星期</th>
                    <th width="40">日志状态</th>
                    <th width="80">操作记录</th>
                    <th width="250">日志详情</th>
                </tr>
             </thead>
			 <tbody class="page-content" id="page-log"></tbody>
        </table>
       	<!-- 分页 -->
		<div class="pagination" id="page" style="margin-right: 20px"></div> 
		<script>
			Date.prototype.format = function(format)
		    {
		        var o = {
		        "M+" : this.getMonth()+1, //month
		        "d+" : this.getDate(),    //day
		        "h+" : this.getHours(),   //hour
		        "m+" : this.getMinutes(), //minute
		        "s+" : this.getSeconds(), //second
		        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
		        "S" : this.getMilliseconds() //millisecond
		        }
		        if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
		        (this.getFullYear()+"").substr(4 - RegExp.$1.length));
		        for(var k in o)if(new RegExp("("+ k +")").test(format))
		        format = format.replace(RegExp.$1,
		        RegExp.$1.length==1 ? o[k] :
		        ("00"+ o[k]).substr((""+ o[k]).length));
		        return format;
		    }
		   KISSY.use('gallery/pagination/1.1/pagination',function(S, P) {
		   	var $ = S.all;
		   	var totalPage;
		   	var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
		   	OnSaleService.count(function(page){
		   		totalPage = page;
		   		var content = S.one('#page-log');
		   		var pagination = new P({
			        container: '#page',
			        template: S.one('#default-pagination-tpl').html(),
			        totalPage: Math.ceil(totalPage/10),
			        callback: function(idx, pg, ready) {
			            content.html('').addClass('loading');
			            OnSaleService.select((idx-1)*10,totalPage,function(data){
			            	var html = '';
			            	S.each(data,function(item, i) {
			            		item.state = item.logState? '操作成功':'操作失败';
			            		item.detail = item.logState? '操作'+item.size+'件商品':'商品id：'+item.numIid+'上架失败';
								html += '<tr>'
									   +    '<td>'+(new Date(item.createTime)).format('yyyy年MM月dd日 hh:mm:ss')+'</td>'
									   +    '<td>'+weekDay[new Date(item.createTime).getDay()]+'</td>'
									   +    '<td>'+item.state+'</td>'
					                   +    '<td>'+item.detail+'</td>'
					                   +    '<td>'+ item.logDetail+'</td>'
					                   +'</tr>';
			                });
		            		content.removeClass('loading').html(html);
		                    ready(idx);
			            });
			        }
			    });
		   	});
		});
		</script> 
	</div>
</body>
</html>
